Test Series - java script

Test Number 58/92

Q: Which of the following is a stateless protocol?
A. HTML
B. XHTML
C. HTTP
D. XML
Solution: A stateless protocol does not require the server to retain information or status about each user for the duration of multiple requests. HTTP is a stateless protocol, which means that the connection between the browser and the server is lost once the transaction ends.
Q: What does the value 2 of the WebSocket attribute Socket.readyState indicate?
A. Closed connection
B. Handshake connection
C. Unestablished connection
D. Established connection and communication is possible
Solution: The WebSocket object provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection. The readonly attribute readyState represents the state of the connection. It can have the following values:
A value of 0 indicates that the connection has not yet been established.
A value of 1 indicates that the connection is established and communication is possible.
A value of 2 indicates that the connection is going through the closing handshake.
A value of 3 indicates that the connection has been closed or could not be opened.
Q: How many WebSocket events are available?
A. 2
B. 3
C. 4
D. 5
Solution: Web sockets are defined as a two-way communication between the servers and the clients, which mean both the parties, communicate and exchange data at the same time. There are fourWebSocket events namely:
open
close
message
error
Q: Which method is used to close the WebSocket?
A. Socket.flush()
B. Socket.close()
C. Socket.Close()
D. Socket.dispose()
Solution: The Socket.close() is used to close the WebSocket. The Close method closes the remote host connection and releases all managed and unmanaged resources associated with the Socket. WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection.
Q: How does the client and the server communicate following the rules defined by the WebSocket protocol?
A. Long-lived TCP Socket
B. Short-lived TCP Socket
C. UDP Socket
D. HTTP Socket
Solution: The client and server communicate over a long-lived TCP socket following rules defined by the WebSocket protocol.
Q: Which of the following is not a socket property?
A. onopen
B. readyState
C. onmessage
D. ready
Solution: There is no Socket property called ready. Various Socket properties include onopen, readystate, ready, binaryTree, onclose, onerror etc.
Q: What does the following JavaScript code snippet do?

var httpserver = new http.Server();
A. Create an HTTP Server
B. Create HTTP Connection between Client and Server
C. HTTP Server & Connection
D. Create a connection between two servers
Solution: HTTP defines what actions Web servers and browsers should take in response to various commands. The above code creates an HTTP Server.
Q: How can we check the subprotocol being used by the client?
A. subprotocol property
B. protocol property
C. clientprotocol property
D. client property
Solution: A WebSocket is a standard bidirectional TCP socket between the client and the server. The socket starts out as an HTTP connection and then “Upgrades” to a TCP socket after an HTTP handshake. Once the connection is established, the client can determine which subprotocol is in use by checking the protocol property of the socket.
Q: How will you transmit data using the connection?
A. send(data)
B. Socket.send(“data”)
C. Socket.send(data)
D. Socket(data)
Solution: The Socket.send(data) method transmits data using the connection. This Socket method sends data to connected socket.
Q: Which of the following is not a WebSocket event?
A. open
B. close
C. error
D. deny
Solution: There is no WebSocket event named deny. The four WebSocket events are
open
close
message
error
Listen to these events using addEventListener() or by assigning an event listener to the oneventname property of this interface.

You Have Score    /10